<?php

namespace Admin\Controller;
use Think\Controller;
use Think\Db;

use Admin\Model\NodeModel;

class NodeController extends BaseController
{
    // 节点列表
    public function index()
    {
        if(IS_AJAX){

            $node = new NodeModel();
            $nodes = $node->getNodeList();

            $nodes = getTree(objToArray($nodes), false);
            return $this->formatjson(msg(1, $nodes, 'ok'));
        }

        return $this->display('node/index');
    }

    // 添加节点
    public function nodeAdd()
    {
        $param = I('param.');

        $node = new NodeModel();
        $flag = $node->insertNode($param);

        return $this->formatjson(msg($flag['code'], $flag['data'], $flag['msg']));
    }

    // 编辑节点
    public function nodeEdit()
    {
        $param = I('param.');

        $node = new NodeModel();
        $flag = $node->editNode($param);

        return $this->formatjson(msg($flag['code'], $flag['data'], $flag['msg']));
    }

    // 删除节点
    public function nodeDel()
    {
        $id = I('param.id');

        $role = new NodeModel();
        $flag = $role->delNode($id);
        return $this->formatjson(msg($flag['code'], $flag['data'], $flag['msg']));
    }
}